{include /common/header}
<script>
    function file_upload(){
        var file = event.target.files[0];
        // 判断是否图片
        if(!file) return ;

        var reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = function(e){
            $.ajax({
                url: '{:\mylib\Route::buildUrl('/admin/api/upload')}',
                type: 'POST',
                dataType: 'json',
                data: {
                    upload_id:'upload_xx',
                    name:file.name,
                    file_data:reader.result
                },
                success:function(res){
                    if (res.code) {
                        $('#' + res.data.upload_id).val(res.data.filename);
                    }else{
                        alert(res.message);
                    }
                },
                error:function(){
                    alert('系统繁忙！');
                }
            });
        }
    }
    function upload_trigger(){
        document.getElementById('upload_form').reset();
        document.getElementById('upload_input').click();
        return false;
    }
</script>
<form id="upload_form" style="display: none;">
    <input type="file" id="upload_input" onchange="file_upload()">
</form>

<form action="{:plugin_url('/slide/admin/add')}" method="POST">
    <fieldset>
        <legend>新增轮播图</legend>

        <div class="form-group">
            <label>标题</label>
            <input type="text" class="form-control" name="title" value="">
        </div>

        <div class="form-group">
            <label>链接地址</label>
            <input type="text" class="form-control" name="url" value="">
        </div>

        <div class="form-group">
            <label>LOGO</label>
            <div class="input-group">
                <input type="text" class="form-control" name="image" value="" id="upload_xx" placeholder="">
                <span class="input-group-btn">
                    <button class="btn btn-default" type="button" onclick="upload_trigger()">上传</button>
                </span>
            </div>
        </div>

        <div class="form-group">
            <label>图片说明</label>
            <textarea class="form-control" name="description"></textarea>
        </div>

        <div class="form-group">
            <label>排序</label>
            <input type="number" class="form-control" name="weight" value="50">
        </div>

        <button type="submit" class="btn btn-primary">提交</button>
        
    </fieldset>
</form>
{include /common/footer}